<?php
	require_once('class_package/common.php');
	$pn = trim($_POST['input_pn']);
	$wsid = trim($_POST['input_wsid']);
	$ver = trim($_POST['webul_mfg_ver']);
	$wo = trim($_POST['input_work_order']);
	$wsid_msg = array();
	
	if ( strpos($wsid,',') > -1 ){
		$get_wsid_array = preg_split("/[\s,]+/",$wsid);
	}else{
		$get_wsid_array[] = $wsid;
	}
	
	if(strpos($wsid,'SOP') === false){
		foreach ( $get_wsid_array as $ws ) {
			$w = $ws .'_SOP';
			$db_select      = Sql_Download::sql_db;
			$db_table       = Sql_Download::sql_table;
			$table_name1    = Sql_Download::table_name1;	// 'webdl_pn';
			$table_name2    = Sql_Download::table_name2;	// 'webdl_wsid';
			$table_name3    = Sql_Download::table_name3;	// 'webdl_tpver';
			$table_name4    = Sql_Download::table_name4;	// 'webdl_work_order';
			$table_name8	= Sql_Download::table_name8;	// 'webdl_create_date';
			$table_name9	= Sql_Download::table_name9;	// 'webdl_creator';
			$table_name10   = Sql_Download::table_name10;	// 'webdl_description';
			
			$conn = mysqli_connect(html::sql_login_host,html::sql_login_user,html::sql_login_pass,$db_select);
			if ( mysqli_connect_errno($conn) ) { 
				echo "<script>alert('MySQL资料库连接错误, 请联系统开发人员!!');history.go(-1);</script>";
				exit();
			}
			
			mysqli_set_charset($conn,'set names utf8');
			$sqli_cmd = "SELECT * FROM `$db_table` WHERE `$table_name1`='$pn' AND `$table_name2`='$w' AND `$table_name3`='$ver' AND `$table_name4`='$wo'";
			$res = mysqli_query($conn,$sqli_cmd);	// 透过 execute_query 对象实例完成查询
			if ( !$res ) { 
				mysqli_close($conn);				// 关闭资料库
				echo "<script>alert('MySQL资料库连接错误, 请联系统开发人员!!');history.go(-1);</script>";
				exit();
			}
			
			$row = mysqli_num_rows($res);		// 返回结果集中栏位的数量。
			if ($row) {
				$msg = 0;
			}else{
				// $msg = '提醒：当前版本 '.$ver.' 对应的SOP不存在'.'请记得同步更新';
				$wsid_msg[] = $ws;
			}
		}
		mysqli_close($conn);	// 关闭资料库 
	}else{
		$msg = 0;
	}
	
	if(count($wsid_msg)!=0){
		$msg = '提醒：当前版本 '.$ver.' 对应的SOP不存在'.'请记得同步更新';
	}
	
	echo $msg;
?>